﻿<UserControl x:Class="DirectoryAnalyzer.Controls.DuplicateFileBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ViewModels="clr-namespace:DirectoryAnalyzer.Controls.ViewModels"
             xmlns:conv="clr-namespace:DirectoryAnalyzer.Controls.Converters"
             xmlns:layout="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
             xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Layout.Toolkit"
             xmlns:uctl="clr-namespace:DirectoryAnalyzer.Controls"
             mc:Ignorable="d" 
             HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
             d:DesignHeight="300" d:DesignWidth="800">

    <Grid Name="grdMainContent">
        <Grid.Resources>
            <ViewModels:DuplicateFileViewModel x:Key="DuplicateFileVM" />
            <conv:VisibilityConverter x:Key="VisibilityConverter" />
            <conv:ExpanderColourConverter x:Key="ExpanderColourConverter" />
            <!--<conv:AccordionSeletionConverter x:Key="AccordionSeletionConverter" />-->
            <Style TargetType="Separator" x:Key="MenuSeparatorStyle">
                <Setter Property="BorderBrush" Value="Gray" />
                <Setter Property="BorderThickness" Value="0.5" />
                <Setter Property="Margin" Value="3,1,3,1" />
            </Style>
            <Style TargetType="MenuItem" x:Key="MenuItemStyle">
                <Setter Property="Margin" Value="0,1,0,1" />
                <Setter Property="FontFamily" Value="Arial" />
                <Setter Property="FontSize" Value="11.25" />
                <Setter Property="Foreground" Value="Black" />
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="HorizontalContentAlignment" Value="Left" />
                <Setter Property="VerticalAlignment" Value="Center" />
                <Setter Property="VerticalContentAlignment" Value="Center" />
            </Style>
            <ContextMenu x:Key="DuplicateItemsMenu" StaysOpen="True">
                <MenuItem Name="mnuDeleteBlock" Header="_Delete block" Click="mnuDeleteBlock_Click" Style="{StaticResource MenuItemStyle}" />
                <MenuItem Name="mnuExpandCollapseBlock" Header="Expand/Collapse _block" Click="mnuExpandCollapseBlock_Click" Style="{StaticResource MenuItemStyle}" />
                <MenuItem Name="mnuExpandAll" Header="_Expand all" Click="mnuExpandAll_Click" Style="{StaticResource MenuItemStyle}" />
                <MenuItem Name="mnuCollapseAll" Header="_Collapse all" Click="mnuCollapseAll_Click" Style="{StaticResource MenuItemStyle}" />
                <Separator Name="sep1" Style="{StaticResource MenuSeparatorStyle}" />

                <MenuItem Name="mnuCheckAll" Header="Check _all" Click="mnuCheckAll_Click" Style="{StaticResource MenuItemStyle}" />
                <MenuItem Name="mnuCheckNone" Header="Check _none" Click="mnuCheckNone_Click" Style="{StaticResource MenuItemStyle}" />
                <Separator Name="sep2" Style="{StaticResource MenuSeparatorStyle}" />

                <MenuItem Name="mnuSuggestDuplicates" Header="_Suggest duplicates" Click="mnuSuggestDuplicates_Click" Style="{StaticResource MenuItemStyle}" />
            </ContextMenu>
        </Grid.Resources>

        <Border Name="brdrMain" BorderThickness="1" BorderBrush="Gray" CornerRadius="5" DataContext="{StaticResource DuplicateFileVM}">
            <ScrollViewer Name="scrlResult" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Beige" 
                          HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible">
                <Grid Name="grdResults">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <layout:Accordion Name="accResult" Grid.Row="0" Margin="0,1,0,0" ItemsSource="{Binding AllDuplicates}" SelectionMode="ZeroOrMore"
                                      HorizontalAlignment="Stretch" Background="Beige" 
                                      SelectedItemsChanged="accResult_SelectedItemsChanged" 
                                      ContextMenu="{StaticResource DuplicateItemsMenu}" ExpandDirection="Down" 
                                      Visibility="{Binding ShowCustom, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}">
                        <!--SelectedItem="{Binding DataContext, Converter={StaticResource AccordionSeletionConverter}}"-->
                        <!--VerticalAlignment="Stretch" :: MS bug :: http://stackoverflow.com/questions/3801708/wpf-accordion-verticalalignment-bug-->
                        <layout:Accordion.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Name="stkHeaderDetailsAcc" Orientation="Vertical" Margin="0,0,0,3" 
                                            HorizontalAlignment="Stretch" VerticalAlignment="Bottom" 
                                            ContextMenu="{StaticResource DuplicateItemsMenu}" Background="DarkGray">
                                    <TextBlock Name="txtbHeaderAcc" Text="{Binding Header}" FontWeight="Bold" 
                                               HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                               ContextMenu="{StaticResource DuplicateItemsMenu}" />
                                    <!--<TextBlock Text="Size" FontWeight="Bold" />
                                    <TextBlock Text="Hash" FontWeight="Bold" />-->
                                </StackPanel>
                            </DataTemplate>
                        </layout:Accordion.ItemTemplate>
                        <layout:Accordion.ContentTemplate>
                            <DataTemplate>
                                <ItemsControl Name="itmctrlDuplicatesAcc" ItemsSource="{Binding Duplicates}" 
                                              ContextMenu="{StaticResource DuplicateItemsMenu}" Background="Red">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Name="stkFilesAcc" Orientation="Horizontal" Margin="0,1,1,1" 
                                                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                                        ContextMenu="{StaticResource DuplicateItemsMenu}">
                                                <TextBlock Name="txtbTreeBranchAcc" Text="|--" TextAlignment="Right" Margin="0,0,1,0" 
                                                           HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                                           ContextMenu="{StaticResource DuplicateItemsMenu}" />
                                                <CheckBox Name="chkSelectionAcc" Content="{Binding FilePath}" Margin="2,0,0,0" 
                                                          HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                                          IsChecked="{Binding IsSelectedForDeletion, Mode=TwoWay}" 
                                                          ContextMenu="{StaticResource DuplicateItemsMenu}" />
                                                <!--Checked="chkSelection_CheckedChanged" Unchecked="chkSelection_CheckedChanged" RKD />-->
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </DataTemplate>
                        </layout:Accordion.ContentTemplate>

                        <!--<layout:Accordion.ItemTemplate>
                            <DataTemplate>
                                <StackPanel ContextMenu="{StaticResource DuplicateItemsMenu}">
                                    <!- -<TextBlock Name="txtbHeaderAcc" Text="{Binding Header}" FontWeight="Bold" VerticalAlignment="Bottom" />- ->
                                    <StackPanel Name="stkHeaderDetailsAcc" Orientation="Vertical" VerticalAlignment="Bottom" Margin="0,0,0,3" ContextMenu="{StaticResource DuplicateItemsMenu}" >
                                        <TextBlock Name="txtbHeaderAcc" Text="{Binding Header}" FontWeight="Bold" VerticalAlignment="Bottom" ContextMenu="{StaticResource DuplicateItemsMenu}" />
                                        <!- -<TextBlock Text="Size" FontWeight="Bold" />
                                            <TextBlock Text="Hash" FontWeight="Bold" />- ->
                                    </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                        </layout:Accordion.ItemTemplate>
                        <layout:Accordion.ContentTemplate>
                            <DataTemplate>
                                <ItemsControl Name="itmctrlDuplicatesAcc" ItemsSource="{Binding Duplicates}" ContextMenu="{StaticResource DuplicateItemsMenu}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Name="stkFilesAcc" SizeChanged="accAccordion_StateChanged" ContextMenu="{StaticResource DuplicateItemsMenu}">
                                                <TextBlock Name="txtbTreeBranchAcc" Text="|- -" TextAlignment="Right" Margin="0,0,1,0" 
                                                           ContextMenu="{StaticResource DuplicateItemsMenu}" 
                                                           HorizontalAlignment="Stretch" VerticalAlignment="Center" />
                                                <CheckBox Name="chkSelectionAcc" Content="{Binding FilePath}" Margin="2,0,0,0" 
                                                          ContextMenu="{StaticResource DuplicateItemsMenu}" 
                                                          HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                                          IsChecked="{Binding IsSelectedForDeletion, Mode=TwoWay}" />
                                                <!- -Checked="chkSelection_CheckedChanged" Unchecked="chkSelection_CheckedChanged" RKD - ->
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </DataTemplate>
                        </layout:Accordion.ContentTemplate>

                        <!- -<HeaderedItemsControl>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel>

                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </HeaderedItemsControl>- -> -->
                    </layout:Accordion>

                    <ItemsControl Name="itmctrlResult" Grid.Row="1" Margin="0,2,0,2" ItemsSource="{Binding AllDuplicates}" 
                                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                  Visibility="{Binding ShowCustom, Converter={StaticResource VisibilityConverter}}" >
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border Name="brdrResult" BorderThickness="1" CornerRadius="2" Margin="5,2,5,2" 
                                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                        ContextMenu="{StaticResource DuplicateItemsMenu}">
                                    <Border.BorderBrush>
                                        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                                            <GradientStop Color="{Binding IsResultExpanded, Converter={StaticResource ExpanderColourConverter}, ConverterParameter=Color}" Offset="0" />
                                            <GradientStop Color="Black" Offset="1" />
                                        </LinearGradientBrush>
                                    </Border.BorderBrush>
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="1,0.2" StartPoint="0,0.2">
                                            <GradientStop Color="White" Offset="0" />
                                            <GradientStop Color="{Binding IsResultExpanded, Converter={StaticResource ExpanderColourConverter}, ConverterParameter=Color}" Offset="1" />
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <StackPanel Name="stkDuplicates" Orientation="Vertical" Margin="5,2,5,3" 
                                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                                ContextMenu="{StaticResource DuplicateItemsMenu}">
                                        <StackPanel Name="stkHeader" Orientation="Horizontal" 
                                                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                                    ContextMenu="{StaticResource DuplicateItemsMenu}">
                                            <Border Height="21" Width="21" CornerRadius="10" BorderThickness="1" 
                                                    HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                                    BorderBrush="{Binding IsResultExpanded, Converter={StaticResource ExpanderColourConverter}, ConverterParameter=Brush}"
                                                    Background="{Binding IsResultExpanded, Converter={StaticResource ExpanderColourConverter}, ConverterParameter=Color}">
                                                <Expander Name="expndrExpandCollapse" IsExpanded="{Binding IsResultExpanded, Mode=TwoWay}" 
                                                          HorizontalAlignment="Left" VerticalAlignment="Center" Margin="-2" 
                                                          ContextMenu="{StaticResource DuplicateItemsMenu}" Background="Transparent"
                                                          Expanded="accAccordion_StateChanged" Collapsed="accAccordion_StateChanged" />
                                                <!--Height="23" Width="23"-->
                                                <!--BorderThickness="0.5" BorderBrush="{Binding IsResultExpanded, Converter={StaticResource ExpanderColourConverter}, ConverterParameter=Brush}"-->
                                            </Border>
                                            <StackPanel Name="stkHeaderDetails" Orientation="Vertical" Margin="3,5,0,3" 
                                                        HorizontalAlignment="Stretch" VerticalAlignment="Bottom" 
                                                        ContextMenu="{StaticResource DuplicateItemsMenu}">
                                                <TextBlock Name="txtbHeader" Text="{Binding Header}" FontWeight="Bold" 
                                                           HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                                           ContextMenu="{StaticResource DuplicateItemsMenu}" />
                                                <!--<TextBlock Text="Size" FontWeight="Bold" />
                                                <TextBlock Text="Hash" FontWeight="Bold" />-->
                                            </StackPanel>
                                        </StackPanel>
                                        <Border Name="brdrDuplicates" BorderThickness="0.5" BorderBrush="Transparent" Margin="35,2,0,3" 
                                                ContextMenu="{StaticResource DuplicateItemsMenu}"
                                                Visibility="{Binding ElementName=expndrExpandCollapse, Path=IsExpanded, Converter={StaticResource VisibilityConverter}}" >
                                            <ItemsControl Name="itmctrlDuplicates" ItemsSource="{Binding Duplicates}" 
                                                          ContextMenu="{StaticResource DuplicateItemsMenu}">
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel Name="stkFiles" Orientation="Horizontal" Margin="0,1,1,1" 
                                                                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                                                    ContextMenu="{StaticResource DuplicateItemsMenu}">
                                                            <TextBlock Name="txtbTreeBranch" Text="|--" TextAlignment="Right" Margin="0,0,1,0" 
                                                                       HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                                                       ContextMenu="{StaticResource DuplicateItemsMenu}" />
                                                            <CheckBox Name="chkSelection" Content="{Binding FilePath}" Margin="2,0,0,0" 
                                                                      HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                                                      IsChecked="{Binding IsSelectedForDeletion, Mode=TwoWay}" 
                                                                      ContextMenu="{StaticResource DuplicateItemsMenu}" />
                                                            <!--Checked="chkSelection_CheckedChanged" Unchecked="chkSelection_CheckedChanged" RKD />-->
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </Border>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Grid>
            </ScrollViewer>
        </Border>
    </Grid>
</UserControl>
